package com.ocom.payhandle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.payconfig.EntityDishesPrice;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payhandle.dao.IDaoDishesPrice;
import com.ocom.payhandle.service.DishesPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DishesPriceServiceImpl extends ServiceImpl<IDaoDishesPrice, EntityDishesPrice> implements DishesPriceService {

	@Autowired
	private IDaoDishesPrice iDaoDishesPrice;


	@Override
	@DataSourceAspect(type = DataSourceEnum.PART_DB, companyId = "comId", isMaster = MasterSlaveEnum.SLAVE)
	public List<EntityDishesPrice> selectDishesPriceList(Long comId, Integer merchId, Integer pointId, List<Integer> dishesIds) {
		QueryWrapper<EntityDishesPrice> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("com_id", comId);
		queryWrapper.eq("merch_id", merchId);
		if (dishesIds.size() == 1) {
			queryWrapper.eq("dishes_id", dishesIds.get(0));
		} else {
			queryWrapper.in("dishes_id", dishesIds);
		}
		queryWrapper.and(wrapper -> {
			wrapper.or().eq("point_id", 0).or().eq("point_id", pointId);
		});
		queryWrapper.orderByDesc("dishes_id", "price_mode", "point_id");
		return this.list(queryWrapper);
	}


}
